package test1.Demo1;

/**
 * ClassName Person
 * Description TODO
 * Author Yanyan
 * Date 2025/11/8 19:08
 * Version 1.0
 */
public class Person {
    //非静态的成员变量  静态成员变量
    private String name;
    private int age = 9;
    //age = 19;  //Error

    //在没有提供任何构造方法时，Java自动提供一个不带参数的构造方法
    public Person() {
        System.out.println("不带参数的构造方法");
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("带有两个参数的构造方法");
    }

    public void eat() {
        System.out.println(this.name + "吃饭");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
